package com.epalmpay.controller.ys.index;

import com.epalmpay.commom.BaseController;
import com.epalmpay.status.Rescode;
import com.epalmpay.dto.shopindex.ShopIndexInDTO;
import com.epalmpay.dto.shopindex.ShopIndexListOutDTO;
import com.epalmpay.service.ys.indexService.IYsIndexService;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;

/**
 * Created by gwn  on 2017/9/11.
 */
public class YsShopIndexController  extends BaseController{


    @Resource
    private IYsIndexService ysIndexService;


    @RequestMapping(value="/index")
    @ResponseBody
    public ShopIndexListOutDTO shopIndex(ShopIndexInDTO shopIndexInDTO){


        ShopIndexListOutDTO shopIndexListOutDTO= new ShopIndexListOutDTO();

        try {

           /* //银行卡数据
            TradeOffline tradeOffline = indexService.queryCardData(shopIndexInDTO);
            shopIndexListOutDTO.setTradeOffline(tradeOffline);
            //扫码付收银
            TradeOffline tradeOffline2 = indexService.queryScanData(shopIndexInDTO);
            shopIndexListOutDTO.setTradeOffline2(tradeOffline2);
            //钱包收银
            TradeOffline tradeOffline3 = indexService.queryWalletData(shopIndexInDTO);
            shopIndexListOutDTO.setTradeOffline3(tradeOffline3);
            //台卡收银
            TradeOffline tradeOffline4 = indexService.queryDeskCardData(shopIndexInDTO);
            shopIndexListOutDTO.setTradeOffline4(tradeOffline4);
            //核销劵码
            OrderServiceGoodDetail orderServiceGoodDetail = indexService.queryOrderData(shopIndexInDTO);
            shopIndexListOutDTO.setOrderServiceGoodDetail(orderServiceGoodDetail);

            //今日目前收益总金额 //现金的
            TradeOffline tradeOffline7 = indexService.queryMoney(shopIndexInDTO);
            shopIndexListOutDTO.setTradeOffline7(tradeOffline7);



            //会员消费人数(线上线下的相加)
            TradeOffline tradeOffline6 = new TradeOffline();
            int count = indexService.queryMemberSum(shopIndexInDTO);
            tradeOffline6.setTotalCount(count);
            shopIndexListOutDTO.setTradeOffline6(tradeOffline6);



            //发展会员人数
            Member member = new Member();
            int sum = indexService.queryDevMemberSum(shopIndexInDTO);
            member.setSum(sum);
            shopIndexListOutDTO.setMember(member);
            //核销劵码
            OrderServiceGoodDetail orderServiceGoodDetail2 = new  OrderServiceGoodDetail();
            int sum2 = indexService.querySum(shopIndexInDTO);
            orderServiceGoodDetail2.setTotalCount(sum2);
            shopIndexListOutDTO.setOrderServiceGoodDetail2(orderServiceGoodDetail2);
            //核销优惠卷   //发优惠卷暂时未0
            CouponUser couponuser = new CouponUser();
            int totalSum = indexService.queryCouponUserCount(shopIndexInDTO);
            couponuser.setTotalSum(totalSum);
            shopIndexListOutDTO.setCouponUser(couponuser);

            //自建商品订单数
//		MallGood mallGood = indexService.queryMallGoodData(shopIndexInDTO);
//		shopIndexListOutDTO.setMallGood(mallGood);
            //自建商品订单数
            OrderServiceGood orderServiceGood = indexService.queryOrderServiceGoodCount(shopIndexInDTO);
            shopIndexListOutDTO.setOrderServiceGood(orderServiceGood);
            //自建商品订单金额
            TradeOffline tradeOffline5 = indexService.queryOrderAmount(shopIndexInDTO);
            shopIndexListOutDTO.setTradeOffline5(tradeOffline5);


            //评价信息
            StatisShop statisShop = indexService.queryStarSum(shopIndexInDTO);
            shopIndexListOutDTO.setStatisShop(statisShop);
            //服务商信息
            Shop shop = indexService.queryShopData(shopIndexInDTO);
            shopIndexListOutDTO.setShop(shop);

            //参与活动
            List<GroupActivityBaseOutDTO> groupActivityBaseOutDTOList =indexService.queryShopActivity(shopIndexInDTO);
            for (GroupActivityBaseOutDTO groupActivityBaseOutDTO : groupActivityBaseOutDTOList) {
                if (groupActivityBaseOutDTO.getEndTime()!=null) {
                    Long time1= groupActivityBaseOutDTO.getEndTime().getTime();
                    System.out.println(time1);
                    Long time2 = new Date().getTime();
                    if (time1-time2>0 && time1!=253402185600000l) {
                        groupActivityBaseOutDTO.setDay((int) ((time1-time2)/86400000));//得到天
                    }else if (time1-time2<0  && time1!=253402185600000l) {
                        groupActivityBaseOutDTO.setDay(-1);//表示已过期
                    }else if( time1==253402185600000l){
                        groupActivityBaseOutDTO.setDay(0);
                    }
                }else{
                    groupActivityBaseOutDTO.setDay(0);
                }

            }
            shopIndexListOutDTO.setActivityBaseOutDTOList(groupActivityBaseOutDTOList);

            //最近30天会员消费人次(线上和线下的相加)
            List<MemberCountOfflineOutDTO> tradeOfflineMemberList = indexService.queryMonthMemberConsumeCount(shopIndexInDTO);
            shopIndexListOutDTO.setTradeOfflineMemberCountList(tradeOfflineMemberList);
            //最近会员发展人数
            List<Member> memberList = indexService.queryDevMemberCount(shopIndexInDTO);
            shopIndexListOutDTO.setMemberList(memberList);

            //最近30天会员消费人次 和发展会员
//		List<StatisShopDay> ststisShopDayList = indexService.queryMemberMonthData(shopIndexInDTO);
//		shopIndexListOutDTO.setStatisShopDay(ststisShopDayList);

            //最近30天的核销劵码 数 和核销金额
            List<OrderServiceGoodDetail> orderServiceGoodDetailList = indexService.queryOrderServiceGoodDetailData(shopIndexInDTO);
            shopIndexListOutDTO.setOrderServiceGoodDetailList(orderServiceGoodDetailList);

            //最近30天的核销优惠卷数量 和已发放数量(没有的暂时是0)
            List<CouponUser> couponUserList = indexService.queryCouponUserData(shopIndexInDTO);
            shopIndexListOutDTO.setCouponUserList(couponUserList);

            //最近一个月的商品订单数和自建商品订单金额
            List<OrderServiceGood> orderServiceGoodList = indexService.queryMonthOrderNum(shopIndexInDTO);
            shopIndexListOutDTO.setOrderServiceGoodList(orderServiceGoodList);
            //最近一个月的商品自建金额
            List<TradeOffline> tradeOfflineList = indexService.queryMonthOrderAmount(shopIndexInDTO);
            shopIndexListOutDTO.setTradeOfflineList(tradeOfflineList);*/

            shopIndexListOutDTO.setErrorCode(Rescode.SUCCESS, "处理成功");
            return shopIndexListOutDTO;
        }
//        catch (ApplicationException ae) {
//            shopIndexListOutDTO.setErrorCode(ae.errCode, ae.errMsg);
//            ae.printStackTrace();
//
//        }
        catch (Exception e) {
            shopIndexListOutDTO.setErrorCode(Rescode.DEFAULT_PREFIX, "处理出现异常");
            e.printStackTrace();
        }
        return shopIndexListOutDTO;

    }





}
